<template>
  <el-dialog title="历史批注信息" :visible.sync="centerDialogVisible" width="30%" center append-to-body @close="dialogClose">
    <div>
      <el-form :model="searchForm" ref="searchFrom" size="mini" inline>
        <el-form-item label="批注" prop="comments">
          <el-input v-model="searchForm.comments" placeholder="请输入批注" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="search" type="primary">搜索</el-button>
          <el-button plain type="info" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table style="margin: 20px 0" :data="tableData" border size="mini" stripe v-loading="tableLoading">
      <el-table-column min-width="120" align="center" show-overflow-tooltip>
        <template slot="header">
          <span>
            <el-tooltip effect="dark" content="红色为未确认收到，绿色为确认收到"
                        placement="top"
            >
              <span><i class="el-icon-question"></i>批注</span>
            </el-tooltip>
          </span>
        </template>
        <template slot-scope="scope">
          <span :class="scope.row.received_or_not?'text-green':'text-red'">{{ scope.row.comments }}</span>
        </template>
      </el-table-column>
      <el-table-column width="200" label="时间" prop="created_time" align="center"></el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="searchForm.page"
      :page-sizes="[10,20,50,100, 200, 300, 400]"
      :page-size.sync="searchForm.page_size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <span slot="footer" class="dialog-footer">
    <el-button @click="centerDialogVisible = false" size="mini">关 闭</el-button>
  </span>
  </el-dialog>
</template>

<script>
import { visitCommentsPage } from '@/api/customer/customer'

export default {
  name: 'VisitCommentsHistoryDialog',
  props: {
    customerId: {
      type: Number,
      default: -1
    }
  },
  data() {
    return {
      centerDialogVisible: false,
      tableLoading: false,
      tableData: [],
      searchForm: {
        page: 1,
        page_size: 10,
        customer_id: null,
        comments: null
      },
      listParams: {
        page: 1,
        page_size: 10,
        customer_id: null,
        comments: null
      },
      total: 0
    }
  },
  methods: {
    search() {
      this.searchForm.page = 1
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    getList() {
      this.tableLoading = true
      visitCommentsPage(this.listParams).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
        this.tableLoading = false
      })
    },
    handleSizeChange(val) {
      this.listParams.page_size = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listParams.page = val
      this.getList()
    },
    resetForm() {
      this.$refs.searchFrom.resetFields()
      this.listParams = Object.assign({}, this.searchForm)
      this.getList()
    },
    open() {
      this.centerDialogVisible = true
      this.searchForm.customer_id = this.customerId
      this.listParams.customer_id = this.customerId
      this.getList()
    },
    dialogClose() {
      this.total = 0
      this.searchForm = {
        page: 1,
        page_size: 10,
        customer_id: null,
        comments: null
      }
      this.listParams = {
        page: 1,
        page_size: 10,
        customer_id: null,
        comments: null
      }
      this.tableData = []
      this.$emit('close')
    }
  }
}
</script>

<style scoped>

</style>
